package com.hopu.mybatis02.controler;

import com.hopu.mybatis02.pojo.R;
import com.hopu.mybatis02.service.IBookService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("book")
public class BookController {
    @Resource
    private IBookService bookService;   //调用业务层接口


    /**
     * 根据分类集合查询图书列表
     * @param category   分类集合：玄幻，都市，历史
     * @return
     */
    @PostMapping
    public R getBookList(@RequestBody ArrayList<String> category) {
        return R.ok(bookService.getBookList(category));
    }

    /**
     * 根据图书id获得书籍详情  /book/1获取
     * @param bookId
     * @return
     */

    @GetMapping("{bookId}")
    public R getBookDetail(@PathVariable("bookId") long bookId) {
        return R.ok(bookService.getBookDetailbyId(bookId));
    }
}
